package com.aisile.user.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auther:yry
 * @Date:2024/7/18 0018
 * @VERSON:1.0
 */
@Configuration
public class RabbitConfig {

    // 交换机
    public static final String AUTH_EXCHANGE = "auth_exchange";
    // 队列
    public static final String AUTH_QUEUE = "auth_queue";


    // 声明交建机
    @Bean(AUTH_EXCHANGE)
    public Exchange BLD_EXCHANGE(){
        return ExchangeBuilder.directExchange(AUTH_EXCHANGE).durable(true).build();
    }

    // 声明队列
    @Bean(AUTH_QUEUE)
    public Queue BLD_QUEUE(){
        return new Queue(AUTH_QUEUE,true);
    }



    // 绑定交换机和队列
    @Bean
    public Binding BLD_EXCHANGE_QUEUE(@Qualifier(AUTH_EXCHANGE) Exchange exchange, @Qualifier(AUTH_QUEUE) Queue queue){
        return BindingBuilder.bind(queue).to((DirectExchange) exchange).with("smrz");  // sfrz
    }
}
